package scanner.com.activity;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import com.haha.extend.HeadBar.BaseHeaderView;
import com.haha.extend.HeadBar.ImageInLeftAndRight;

import scanner.com.dialog.ColorWindow;
import scanner.com.scanner.R;

/**
 * Created by Administrator on 2016/7/9.
 */
public class QRMakeActivity extends AppCompatActivity {
    private ImageInLeftAndRight HEADER;
    private View QRBGLAYOUT, COLORBTN, SHAREBTN;
    private ImageView QRIMG;
    private ColorWindow colorWindow;
    private  QRUtils qur;
    private String sr="http://www.baidu.com";




    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qr);
        qur=new QRUtils();
        findView();
        initview();
    }

    private void findView() {
        HEADER = (ImageInLeftAndRight) findViewById(R.id.header_qrsop);
        COLORBTN = findViewById(R.id.co_color);
        SHAREBTN = findViewById(R.id.share_color);
        QRBGLAYOUT = findViewById(R.id.qr_bg);
        QRIMG = (ImageView) findViewById(R.id.qr_img);
        colorWindow = new ColorWindow(QRMakeActivity.this);

    }

    private void initview() {
        HEADER.setOnClickListener(onClickListener);
        COLORBTN.setOnClickListener(onClickListener);
        SHAREBTN.setOnClickListener(onClickListener);
        colorWindow.setOnColorChangedListener(new ColorWindow.OnColorChangedListener() {
            @Override
            public void onBgColorChanged(int color) {
                QRBGLAYOUT.setBackgroundColor(color);
            }

            @Override
            public void onFgColorChanged(int color) {

               QRIMG.setImageBitmap(qur. createQRImage(sr, color,	Color.TRANSPARENT,500,500));

            }
        });

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (colorWindow != null && colorWindow.isShowing()) {
            colorWindow.dismiss();
            colorWindow = null;
        }
    }

    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.co_color:
                    colorWindow.show(COLORBTN);
                    break;

                case R.id.share_color:

                    break;
            }
        }
    };

    private BaseHeaderView.OnHeaderClickListener onHeaderClickListener = new BaseHeaderView.OnHeaderClickListener() {
        @Override
        public void onHeaderLeftClicked() {

        }

        @Override
        public void onHeaderCenterClicked() {

        }

        @Override
        public void onHeaderRightClicked() {

        }
    };
}
